package org.dom4j.tree;

import java.util.List;

import org.dom4j.Attribute;
import org.dom4j.Element;
import org.dom4j.Node;

public class DefaultAttribute implements Attribute {
  
  private String name;
  private String value;
  private Element parent;
  
  DefaultAttribute(Element parent, String name, String value) {
    this.parent = parent;
    this.name = name;
    this.value = value;
  }
  
  public String getValue() {
    return value;
  }

  public void setValue(String value) {
    this.value = value;
  }

  public Node selectSingleNode(String xpath) {
    throw new UnsupportedOperationException();
  }

  public Node detach() {
    this.parent.remove(this);
    this.parent = null;
    return this;
  }

  public List selectNodes(String xpath) {
    throw new UnsupportedOperationException();
  }

  public String getText() {
    throw new UnsupportedOperationException();
  }

  public void setText(String text) {
    throw new UnsupportedOperationException();
  }

  public String getName() {
    return name;
  }

  public String asXML() {
    // escape value chars?
    if (value == null) {
      return "";
    }
    return name + "=\"" + value + "\"";
  }

  public Element getParent() {
    return parent;
  }
  
  public void setParent(Element parent) {
    this.parent = parent;
  }

}
